//1. 安装
//2. 导入
const mongoose = require("mongoose");

//3. 连接 mongodb 数据库
mongoose.connect("mongodb://127.0.0.1:27017/h5220707");

//4. 设置回调  on  when 当...时候
mongoose.connection.on("open", () => {
  //5. 声明文档结构对象 
  const MovieSchema = new mongoose.Schema({
    name: String,
    actors: Array,
    releaseYear: Number,
  });

  //6. 创建文档模型对象
  const MovieModel = mongoose.model("movie", MovieSchema);

  //7. 文档操作
  //删除
  // MovieModel.deleteMany({name: '让子弹飞'}, (err,data) => {
  //   if(err) throw err;
  //   console.log(data);
  //   //关闭链接
  //   mongoose.connection.close();
  // });

  MovieModel.deleteOne({_id: '632e7f932b5e41d5d06337ef'},(err,data) => {
    if(err) throw err;
    console.log(data);
    mongoose.connection.close();
  })
  
});

/**
 * 1. 注销账号
 * 2. 删除评论
 * 3. 下架
 * > 实际项目, 几乎不会删除数据
 */
